//
//  SKUnLoginTableViewController.swift
//  WeiboProject
//
//  Created by yanli on 16/7/9.
//  Copyright © 2016年 mountainPassCell. All rights reserved.
//

import UIKit

class SKUnLoginTableViewController: UITableViewController {
    //判断是否登录的条件
    //  SKUserAccountViewModel 封装OAuth登录相关接口
    var isLogin :Bool = SKUserAccountViewModel.shareUserAccount.isLogin
    
    // 访客视图 
    var vistorView: SKVistorView?
    
    override func loadView() {
        
        //判断是否登录
        if isLogin {
            //登录
            super.loadView()
            
        } else {
            // 未登录
            vistorView = SKVistorView()
            //  使用[weak self]解决闭包循环引用
            vistorView?.loginClosure = { [weak self] in
                print("点击了 访客视图里面登录或者注册",self)
                
                //调用 登录方法
                self?.showOAuthLogin()
                    
            }
            
            view = vistorView
            
            //  设置导航视图
            setupNavUI()
        }
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }

    
    
    
    //  设置导航视图
    private func setupNavUI() {
        
        
        //这个地方 代码抽取到UIBarButtonItem分类中
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "registerAction")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginAction")
        
    }
    
    
    // MARK: -- 点击事件
    // 注册
    @objc private func registerAction() {
        print("registerAction")
        showOAuthLogin()
    }
    
    //登录
    @objc private func loginAction() {
        print("loginAction")
        showOAuthLogin()
    }
    
    
    //OAuth 登录页面
    private func showOAuthLogin() {
        let oAuthVC = SKOAuthViewController()
        let nav = UINavigationController(rootViewController: oAuthVC)
        //跳转
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
    
    
    
    
    
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

  
    

}








